using System;
using Microsoft.Xna.Framework;

namespace GameFramework.Extensions
{
    /// <summary>
    /// Useful extension methods for Vector2.
    /// </summary>
    public static class Vector2Extensions
    {
        /// <summary>
        /// Convert the vector into a Point.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <returns>The corresponded point.</returns>
        public static Point ToPoint(this Vector2 vector)
        {
            return new Point((int)vector.X, (int)vector.Y);
        }

        /// <summary>
        /// Return a vector rotated around origin by a specific angle.
        /// </summary>
        /// <param name="vector">The vector.</param>
        /// <param name="angle">The angle.</param>
        /// <returns>The new rotated vector.</returns>
        public static Vector2 RotateAroundOriginByAngle(this Vector2 vector, float angle)
        {
            return new Vector2(
                (float)(Math.Cos(angle) * vector.X - Math.Sin(angle) * vector.Y),
                (float)(Math.Sin(angle) * vector.X + Math.Cos(angle) * vector.Y));
        }
    }
}
